package com.shop.goods.controller;

import com.shop.domain.Product;
import com.shop.entity.Result;
import com.shop.goods.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品表
 */
@RestController
@RequestMapping("/Product")
public class ProductController {
    @Autowired
    private ProductService iProductService;

    /**
     * 查询全部商品表
     * @param
     * @return
     */
    @GetMapping("/selectAll")
    public Result<List<Product>> selectAll(){
        return new Result<>("查询成功",iProductService.selectAll());
    }


    /**
     * 条件查询商品表
     * @param iProduct
     * @return
     */
    @PostMapping("/selectList")
    public Result< List<Product> > select(@RequestBody Product iProduct){
        return new Result<>("条件查询成功",iProductService.selectList(iProduct));
    }

    /**
     * 新增商品表
     * @param iProduct
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Product iProduct){
        iProductService.insert(iProduct);
        return new Result<>("新增成功");
    }


    /**
     * 删除商品表
     * @param ids
     * @return
     */
    @GetMapping("/delete")
    public Result delete(@RequestParam String ids){
        iProductService.delete(ids);
        return new Result<>("删除成功");
    }


    /**
     * 修改商品表
     * @param iProduct
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Product iProduct){
        iProductService.update(iProduct);
        return new Result<>("修改成功");
    }

    /**
     * 商品审核
     * @param id
     * @param audit
     * @return
     */
    @PostMapping("/audit")
    public Result audit(@RequestParam Long id,@RequestParam Integer audit){
        Integer i =

                iProductService.audit(id,audit);
        if(i==-1){
            return new Result("审核失败");
        }else if(i==2){
            return new Result("审核拒绝");
        }
        return new Result("审核成功");
    }

    /**
     * 上下架
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/status")
    public Result status(@RequestParam Integer id,@RequestParam Integer status){
        Integer i = iProductService.status(id,status);
        if(i==-1){
            return new Result("上下架失败");
        }if(status==0){
            return new Result("下架成功");
        }
        return new Result("上架成功");
    }

}
